using System;
using System.IO;
using System.Diagnostics;
using System.ComponentModel;
using SoftwareMonkeys.Scriptech.Scripts;

namespace SoftwareMonkeys.Scriptech.Web
{
	public class Screenshots
	{
		SoftwareMonkeys.Scriptech.Scripts.Console CurrentConsole = null;
		
		public Screenshots()
		{
		}
	
		public Screenshots (SoftwareMonkeys.Scriptech.Scripts.Console console)
		{
			CurrentConsole = console;
		}
		
		public void Create(string url, string outputPath)
		{
			//string libDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().FullName);
			
			string captureAppPath = "bin" + Path.DirectorySeparatorChar + "CutyCapt";
			
			ProcessStartInfo info = new ProcessStartInfo();
			
			info.FileName = captureAppPath;
			info.Arguments = "--url=" + url + " --out=" + outputPath;
			
			info.UseShellExecute = false;
			info.RedirectStandardError = true;
			info.RedirectStandardOutput = true;
			
			Process process = new Process();
			process.StartInfo = info;
			
			
			try{
			
			process.Start();
			}
			catch (Win32Exception ex)
			{
				//string error = String.Empty;
				//if (process.StandardErrorprocess.StandardError.ReadToEnd();
				
				//string output = process.StandardOutput.ReadToEnd();
				
			throw ex;
				//throw new Exception(error, ex);
			}
				
			/*if (CurrentConsole != null)
			{
				if (output != null)
					CurrentConsole.Write(output);
				if (error != null)
					CurrentConsole.Write(error);
			}*/
			
			process.WaitForExit();
			
			
		}
	}
}

